import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import plotly.express as px
import os
DATA_FOLDER = os.getcwd()
print(DATA_FOLDER)
/Users/radhika/Downloads
%cd /Users/radhika/Downloads/Radhika-maps/Stories
/Users/radhika/Downloads/Radhika-maps/Stories
DATA_FOLDER = os.getcwd()
print(DATA_FOLDER)
/Users/radhika/Downloads/Radhika-maps/Stories
PREPROCESS_FOLDER = f"{DATA_FOLDER}/population_plot"
OUTPUT_FOLDER = f"{DATA_FOLDER}/output"
DF_CSV = f"{PREPROCESS_FOLDER}/Data_2095.csv"
Splot_HTML_OUTPUT = f'{OUTPUT_FOLDER}/tfrvsbirth_index.html'
df = pd.read_csv(DF_CSV)
df.head()
| S.no. | Year | State | TFR | Pop | PR | Birth | BR | |
|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2010 | andaman & nicobar islands | 1.59 | 380572 | 0.096029 | 28926 | 0.026965 |
| 1 | 2 | 2010 | andhra pradesh | 1.77 | 84573062 | 0.046867 | 7020689 | -0.035690 |
| 2 | 3 | 2010 | arunachal pradesh | 1.86 | 1383715 | 0.094695 | 116947 | 0.077787 |
| 3 | 4 | 2010 | assam | 2.53 | 31205555 | 0.073214 | 3539909 | -0.028166 |
| 4 | 5 | 2010 | bihar | 3.41 | 104097888 | 0.082118 | 13015567 | -0.015003 |
type(df['Pop'])
pandas.core.series.Series
df = df.rename(columns={'BR':'Birth Rate','TFR':'Total Fertility Rate'})
df['Pop']= df['Pop'].astype(int)
df['Birth']=df['Birth'].astype(int)
df['Pop in Million']=df['Pop']/1000000
df['Birth per Thousand']=df['Birth']/1000
df.head()
| S.no. | Year | State | Total Fertility Rate | Pop | PR | Birth | Birth Rate | Pop in Million | Birth per Thousand | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2010 | andaman & nicobar islands | 1.59 | 380572 | 0.096029 | 28926 | 0.026965 | 0.380572 | 28.926 |
| 1 | 2 | 2010 | andhra pradesh | 1.77 | 84573062 | 0.046867 | 7020689 | -0.035690 | 84.573062 | 7020.689 |
| 2 | 3 | 2010 | arunachal pradesh | 1.86 | 1383715 | 0.094695 | 116947 | 0.077787 | 1.383715 | 116.947 |
| 3 | 4 | 2010 | assam | 2.53 | 31205555 | 0.073214 | 3539909 | -0.028166 | 31.205555 | 3539.909 |
| 4 | 5 | 2010 | bihar | 3.41 | 104097888 | 0.082118 | 13015567 | -0.015003 | 104.097888 | 13015.567 |
fig= px.scatter(df,x= "Total Fertility Rate", y= "Birth per Thousand", animation_frame="Year", animation_group="State",size="Pop in Million",color="State",
hover_data={'Birth per Thousand' :True,'State' :True, 'Pop in Million' :True,'Total Fertility Rate' :True},
log_x=False, size_max=90, title='Birth vs TFR'
)
fig.update_layout(yaxis_title="Birth per Thousand", plot_bgcolor='black',paper_bgcolor='black')
fig.update_xaxes(showgrid=False)
fig.update_yaxes(showgrid=False)
fig.update_layout(width=1000, height=800)
fig.update_layout(
font=dict(
color='white'
)
)
fig.write_html(Splot_HTML_OUTPUT)
fig